package com.xqls.server.dto.recive;

import com.xqls.biz.SokectBiz;
import com.xqls.server.dto.SoketCommonDto;
import com.xqls.server.netty.DecoderUtil;
import com.xqls.util.ContextUtil;
import com.xqls.util.Retaindecimal;
import io.netty.buffer.ByteBuf;

import java.util.Date;

/**
 * 采样仪水质因子实时值
 */
public class SamplingRealTimeDto extends SoketCommonDto {
	
	/**
	 * 水泵电流
	 * 需要/100后处理
	 */
	
	private Integer electricCurrent;
    /**
     * 瞬时流量
     */
    private Double instantaneousMeasure;

    private Double UV;

    private Double SS;


    private Double PH;

    /**
     * 实时氨氮值
     */
    private Double ammoniaValue;

    /**
     * 保留
     */
    private Short  retain;

    /**
     累计流量
     */
    private Long  accumulativeTotal;

    /**
     *  记录时间
     */
    private Date time;


    /**
     * 实时温度
     */
    private Double temperature;


    public Double getInstantaneousMeasure() {
        return instantaneousMeasure;
    }

    public void setInstantaneousMeasure(Double instantaneousMeasure) {
        this.instantaneousMeasure = instantaneousMeasure;
    }

    public Double getTemperature() {
        return temperature;
    }

    public void setTemperature(Double temperature) {
        this.temperature = temperature;
    }

    public Double getUV() {
        return UV;
    }

    public void setUV(Double UV) {
        this.UV = UV;
    }

    public Double getSS() {
        return SS;
    }

    public void setSS(Double SS) {
        this.SS = SS;
    }

    public Double getPH() {
        return PH;
    }

    public void setPH(Double PH) {
        this.PH = PH;
    }

    public Double getAmmoniaValue() {
        return ammoniaValue;
    }

    public void setAmmoniaValue(Double ammoniaValue) {
        this.ammoniaValue = ammoniaValue;
    }

    public Long getAccumulativeTotal() {
        return accumulativeTotal;
    }

    public void setAccumulativeTotal(Long accumulativeTotal) {
        this.accumulativeTotal = accumulativeTotal;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    public Short getRetain() {
        return retain;
    }

    public void setRetain(Short retain) {
        this.retain = retain;
    }

    public Integer getElectricCurrent() {
		return electricCurrent;
	}

	public void setElectricCurrent(Integer electricCurrent) {
		this.electricCurrent = electricCurrent;
	}

	protected void decode(ByteBuf in, SoketCommonDto soketCommonDto){
        Retaindecimal retaindecimal=new Retaindecimal();
        SamplingRealTimeDto samplingDto=(SamplingRealTimeDto)soketCommonDto;
        samplingDto.setInstantaneousMeasure(retaindecimal.divideTen(DecoderUtil.shortToInt(in.readShort())));
        samplingDto.setUV(retaindecimal.divideTen(DecoderUtil.shortToInt(in.readShort())));
        samplingDto.setSS(retaindecimal.divideTen(DecoderUtil.shortToInt(in.readShort())));
        samplingDto.setPH(retaindecimal.divideHundred(DecoderUtil.shortToInt(in.readShort())));
        samplingDto.setAmmoniaValue(retaindecimal.divideHundred((DecoderUtil.shortToInt(in.readShort()))));
        samplingDto.setElectricCurrent(DecoderUtil.shortToInt(in.readShort())*100);
        samplingDto.setAccumulativeTotal(Long.valueOf(DecoderUtil.fourToHex(in),16));
        samplingDto.setTemperature(retaindecimal.divideHundred(DecoderUtil.shortToInt(in.readShort())));
        samplingDto.setRetain(in.readShort());//多出来的4个字节忽略保留


        samplingDto.setTime(DecoderUtil.getBCDDate(in));
        super.decode(in,soketCommonDto);
    }


    public void operate( ){
        SokectBiz sokectBiz=(SokectBiz) ContextUtil.getBean(SokectBiz.class);
        sokectBiz.samplingRealTimeRecive(this);


    }


}
